package com.heng.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heng.dao.entity.Product;
import com.heng.dto.ProductDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 商品Mapper（继承MyBatis-Plus BaseMapper，无需写基础CRUD）
 */
public interface ProductMapper extends BaseMapper<Product> {

    /**
     * 分页查询精选商品（注解方式，无需XML）
     * @param page 分页参数
     * @return 分页后的商品DTO列表
     */
    @Select("SELECT id, title, img_url, quality, delivery, rating, review_count, " +
            "price/100 AS price, original_price/100 AS original_price " +
            "FROM product WHERE is_featured = 1 ORDER BY create_time DESC")
    IPage<ProductDTO> selectFeaturedProducts(Page<ProductDTO> page);

    /**
     * 分页查询新品商品（注解方式）
     * @param page 分页参数
     * @return 分页后的商品DTO列表
     */
    @Select("SELECT id, title, img_url, quality, delivery, rating, review_count, " +
            "price/100 AS price, original_price/100 AS original_price " +
            "FROM product WHERE is_new = 1 ORDER BY create_time DESC")
    IPage<ProductDTO> selectNewProducts(Page<ProductDTO> page);
}